# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer:
pkgname=shiboken2
pkgver=5.15.10
pkgrel=0
pkgdesc="CPython bindings generator for C++ libraries"
url="https://wiki.qt.io/Qt_for_Python/Shiboken"
arch="all !armhf" # qt5-qtxmlpatterns -> qt5-qtdeclarative
license="GPL-2.0-or-later"
_llvmver=15
depends_dev="python3-dev"
makedepends="
	$depends_dev
	clang$_llvmver-dev
	cmake
	libxml2-dev
	libxslt-dev
	llvm$_llvmver-dev
	py3-numpy-dev
	py3-setuptools
	qt5-qtbase-dev
	qt5-qtxmlpatterns-dev
	samurai
	"
subpackages="lib$pkgname:libs lib$pkgname-dev py3-$pkgname:py3"
source="https://download.qt.io/official_releases/QtForPython/pyside2/PySide2-$pkgver-src/pyside-setup-opensource-src-$pkgver.tar.xz
	numpy-1.23.patch
	py3.11.patch
	"
builddir="$srcdir/pyside-setup-opensource-src-$pkgver"

provides="shiboken=$pkgver-r$pkgrel" # For backward compatibility
replaces="shiboken" # For backward compatibility

prepare() {
	default_prepare
	sed -e 's|0x030AFFFF|0x030BFFFF|' -i sources/shiboken2/libshiboken/pep384impl.h
}

build() {
	export LLVM_INSTALL_DIR=/usr/lib/llvm$_llvmver
	cmake -B build -S sources/shiboken2 \
		-G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_TESTS=OFF \
		-DUSE_PYTHON_VERSION=3
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

libs() {
	license="LGPL-2.1-or-later"
	default_libs
}

dev() {
	license="LGPL-2.1-or-later"
	default_dev
	provides="shiboken-dev=$pkgver-r$pkgrel"
	replaces="shiboken-dev"
	depends="
		$depends_dev
		lib$pkgname=$pkgver-r$pkgrel
		$pkgname=$pkgver-r$pkgrel
		py3-$pkgname=$pkgver-r$pkgrel
		"
}

py3() {
	license="LGPL-2.1-or-later"
	depends=""
	pkgdesc="Python3 shiboken bindings"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/python3* "$subpkgdir"/usr/lib
	provides="py3-shiboken=$pkgver-r$pkgrel" # For backward compatibility
	replaces="py3-shiboken" # For backward compatibility

	# Install egg info
	cd "$builddir"
	export PATH="/usr/lib/qt5/bin:$PATH"
	python3 setup.py egg_info --build-type=shiboken2
	pythonpath="$(python3 -c "from sysconfig import get_path; print(get_path('platlib'))")"
	cp -r shiboken2.egg-info "$subpkgdir/$pythonpath"
}

sha512sums="
dc548ab870fcc5cc637de1bcb2f428527c650287fdb3720a3ade4638cc0bb12bc4a1ed87e7f6a4ec730a26742e08ceec806bcac6af91c7a01ddc0ce7980a79d2  pyside-setup-opensource-src-5.15.10.tar.xz
449b4f4b1717b131c05e798549d49186f73215b893843ccae4c434dd95ad3f4dce0f886fe5cbd3443100d4852cb6b3d6a6d2f0a102f69f2a095bb6c500d69244  numpy-1.23.patch
bda0bbf74ed639f4af40322883c65ede03cc0cde46382e9237215e0250ee1a858642e721112fb4ba92bbfb54aed8a2b97dc6dc71734665bbc52e8002ac915bfd  py3.11.patch
"
